﻿using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Resume.Common;
using Resume.IRepository;
using Resume.Repository;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

#region Autofac

builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());

builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
{
    builder.RegisterType<FieldClassDict_Repository>().As<IFieldClassDict_Repository>();
    builder.RegisterType<FiledSetting_Repository>().As<IFieldSetting_Repository>();
    builder.RegisterType<UsersDict_Repository>().As<IUsersDict_Repository>();
});

#endregion

#region AutoMapper

builder.Services.AddAutoMapper(typeof(AutoMapperConfigs));

#endregion

#region Swagger

builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "Resume.Core", Version = "v1", Description = "demo Interface" });

    var file = Path.Combine(AppContext.BaseDirectory, "Resume.System.xml");//XML绝对路径

    var path = Path.Combine(AppContext.BaseDirectory, file); // xml⽂档绝对路径

    c.IncludeXmlComments(path, true);//true 显示控制器层注释

    c.OrderActionsBy(o => o.RelativePath);//对action的名称进行排序，如果有多个，就可以 看到效果了。
});

#endregion
var app = builder.Build();

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
app.UseSwagger();
app.UseSwaggerUI();
//}



app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
